// 红绿灯
// then return promise 链式调用
const traffic_light = (color, duration) => {
  return new Promise((resolve, reject) => {
    console.log('traffic-light', color);
    setTimeout(() => {
      resolve()
    }, duration)
  })
}
// 任何代码都是死循环
const main = () => {
  Promise.resolve()  // fullfiled promise
    .then(() => traffic_light('red', 3000))
    .then(() => traffic_light('yellow', 3000))
    .then(() => traffic_light('green', 3000))
    .then(() => {
      main()
    })
}

main()